package com.itheima.developtest;

import java.util.Random;
import java.util.Scanner;

public class Test03 {
    /*
    随机生成一个验证码,用户键盘录入看是否相同
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            String code = code();
            System.out.print("当前验证码:");
            System.out.println(code);

            String s = sc.next();
            if (s.equals(code)) {
                System.out.println("验证通过...");
                break;
            }
        }
    }

    public static String code() {
        String num = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890";
        StringBuilder sb = new StringBuilder();
        Random r = new Random();
        for (int i = 0; i < 4; i++) {
            int index = r.nextInt(num.length());
            char c = num.charAt(index);
            sb.append(c);
        }
        return sb.toString();
    }
}
